package com.spic.business.accident.interevents.management.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.common.security.annotation.PreAuthorize;
import com.spic.business.accident.interevents.management.domain.InternalIncidentReport;
import com.spic.business.accident.interevents.management.service.IInternalIncidentReportService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * 内部事件管理Controller
 * 
 * @author 任翔
 * @date 2021-12-01
 */
@RestController
@RequestMapping("/accident/internalEvent")
public class InternalIncidentReportController extends BaseController
{
    @Autowired
    private IInternalIncidentReportService internalIncidentReportService;

    /**
     * 查询内部事件管理列表
     */
    @PreAuthorize(hasPermi = "business:InternalEvent:list")
    @GetMapping("/list")
    public TableDataInfo list(InternalIncidentReport internalIncidentReport)
    {
        startPage();
        List<InternalIncidentReport> list = internalIncidentReportService.selectInternalIncidentReportList(internalIncidentReport);
        return getDataTable(list);
    }

    /**
     * 导出内部事件管理列表
     */
    @PreAuthorize(hasPermi = "business:InternalEvent:export")
    @Log(title = "内部事件管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InternalIncidentReport internalIncidentReport) throws IOException
    {
        List<InternalIncidentReport> list = internalIncidentReportService.selectInternalIncidentReportList(internalIncidentReport);
        ExcelUtil<InternalIncidentReport> util = new ExcelUtil<InternalIncidentReport>(InternalIncidentReport.class);
        util.exportExcel(response, list, "内部事件管理数据");
    }

    /**
     * 获取内部事件管理详细信息
     */
    @PreAuthorize(hasPermi = "business:InternalEvent:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(internalIncidentReportService.selectInternalIncidentReportById(id));
    }

    /**
     * 新增内部事件管理
     */
    @PreAuthorize(hasPermi = "business:InternalEvent:add")
    @Log(title = "内部事件管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InternalIncidentReport internalIncidentReport)
    {
        return toAjax(internalIncidentReportService.insertInternalIncidentReport(internalIncidentReport));
    }

    /**
     * 修改内部事件管理
     */
    @PreAuthorize(hasPermi = "business:InternalEvent:edit")
    @Log(title = "内部事件管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InternalIncidentReport internalIncidentReport)
    {
        return toAjax(internalIncidentReportService.updateInternalIncidentReport(internalIncidentReport));
    }

    /**
     * 删除内部事件管理
     */
    @PreAuthorize(hasPermi = "business:InternalEvent:remove")
    @Log(title = "内部事件管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(internalIncidentReportService.deleteInternalIncidentReportByIds(ids));
    }
}
